package org.dey.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.dey.pojo.User;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author deyran
 * @classname
 * @see BaseMapper
 */
@Repository
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT * FROM t_user")
    @Results(id = "UserMapper",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "birthday",property = "birthday"),
            @Result(column = "gender",property = "gender"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "remark",property = "remark"),
            @Result(column = "station",property = "station"),
            @Result(column = "telephone",property = "telephone"),
            @Result(property = "roles",column = "id",many = @Many(select = "org.dey.mapper.RoleMapper.ROLE_ID"))
    })
    @Lazy(false)
    List<User> USERS();

    @Select("SELECT * FROM t_user WHERE " +
            " id = (SELECT user_id FROM t_member_user WHERE member_id = #{id} AND " +
            " user_id = (SELECT id FROM t_user WHERE username = #{username}))")
    List<User> findAllByIdUsers(@Param("id")Integer id, @Param("username")String username);

}
